
/*
 * Copyright (C) 2010 Bitglue. All rights reserved.
 *
 * $Id: EclipseInstanceManager.java bself $
 */

package org.springframework.osgi.web.deployer.eclipse;

import java.lang.reflect.InvocationTargetException;

import javax.naming.NamingException;

import org.apache.tomcat.InstanceManager;

/**
 * EclipseInstanceManager is a stripped down instance manager
 * for use with Jasper. The only hook into cataline from tomcat's
 * japer engine is an {@link InstanceManager}. This instance
 * should be place in the web application context for Jasper 7
 * to execute without catalina.
 * @author Bryan Patrick Self
 */
public class EclipseInstanceManager implements InstanceManager {

    public Object newInstance(String className) throws IllegalAccessException,
      InvocationTargetException, NamingException, InstantiationException,
      ClassNotFoundException {
        Class<?> clazz = this.getClass().getClassLoader().loadClass(className);
        return newInstance(clazz.newInstance(), clazz);
    }

    public Object newInstance(final String className,
      final ClassLoader classLoader) throws IllegalAccessException,
      NamingException, InvocationTargetException, InstantiationException,
      ClassNotFoundException {
        Class<?> clazz = classLoader.loadClass(className);
        return newInstance(clazz.newInstance(), clazz);
    }

    public void newInstance(Object o) throws IllegalAccessException,
      InvocationTargetException, NamingException {
        newInstance(o, o.getClass());
    }

    private Object newInstance(Object instance, Class<?> clazz) throws
      IllegalAccessException, InvocationTargetException, NamingException {
        return instance;
    }

    public void destroyInstance(Object instance) throws
      IllegalAccessException, InvocationTargetException {
    }

}
